Ext.define('NIM.view.AssetChange.DismantleSiteForm',{
					extend : 'Ext.panel.Panel',
					alias : 'widget.DismantleSiteForm',
					id : 'dismantlesiteform',
					border : false,
					title : 'Dismantle Site',
					layout : 'fit',
					//singleton : true,
					closable : true,
					layout : {
						type : 'border'
					},
					width : 1 * screen.width,
					height : 590,
					items : [
							{
							    xtype : 'form',
					            id : 'panelDismantleSite',
					            title : 'Relocation Site Form',
					            region : 'west',
					            margin : '5 5 5 5',
					            autoScroll:true,
					            method : 'POST',
					            url : './Services/AssetChange/Site/Change/Add',
					            collapsible : true,
					            collapsed : true,
					            width : 600,
								items : [
										{

											xtype : 'hiddenfield',
											cls : 'black',
											id : 'dismantlesiteChangeCat',
											name : 'CHANGE_CATEGORY',
											value : "DISMANTLE_SITE",
											margin : '10 10 10 10',
											labelWidth : 100 / 1366 * screen.width,
											width : 300 / 1366 * screen.width,
										},
										{
											xtype : 'fieldcontainer',
											cls : 'black',
											margin : '10 10 10 10',
											fieldLabel : 'SITE ID',
											labelWidth : 130 / 1366 * screen.width,
											width : 325 / 1366 * screen.width,
											layout : 'hbox',
											items : [
													{
														xtype : 'textfield',
														id : 'textSiteIdtDismantleSite',
														name : 'SOURCE_SITE_ID',
														margin : '0 5 0 0',
														width : 135,
														hideLabel : true,
														allowBlank : false

													},
													{
														xtype : 'button',
														//id : 'butSiteIdDismantleSite',
														text : 'Browse',
														width : 50,
														handler : function() {
															openPopup('textSiteIdtDismantleSite','siteNameDismantleSite');
															
														}
													} ]
										},
										{
											xtype : 'textfield',
											fieldLabel : 'SITE NAME',
											id : 'siteNameDismantleSite',
											labelWidth : 130 / 1366 * screen.width,
											width : 325 / 1366 * screen.width,
											margin : '10 10 10 10',
											allowBlank : false

										},
										{
							                  xtype : 'datefield',
							                  minDate : new Date(),
							                  fieldLabel : 'DATE',
							                  name : 'CHANGE_DATE',
							                  // id:'relocationsitedate',
							                  labelWidth : 130 / 1366 * screen.width,
							                  width : 325 / 1366 * screen.width,
							                  margin : '5 10 0 10',
							                  allowBlank : false
						                  
						                }, 
										{
											xtype : 'combo',
											fieldLabel : 'WAREHOUSE',
											id : 'warehouseDismantleSite',
											labelWidth : 130 / 1366 * screen.width,
											width : 325 / 1366 * screen.width,
											margin : '10 10 10 10',
											store : 'Administration.Warehouse',
											displayField : 'WH_CODE',
											valueField : 'WH_ID',
											name       :"DESTINATION"
										},
										{
							                  xtype : 'combobox',
							                  fieldLabel : 'REASON',
							                  name : 'CR_ID',
							                  displayField : 'CHANGE_REASON',
							                  valueField : 'CR_ID',
							                  labelWidth : 130 / 1366 * screen.width,
							                  width : 325 / 1366 * screen.width,
							                  allowBlank : false,
							                  store : 'Administration.AssetChangeReason',
							                  margin : '5 10 10 10',
							                  listeners : {
								                    afterrender : function() {
								                      Ext.getStore('Administration.AssetChangeReason').removeAll();
								                      Ext.getStore('Administration.AssetChangeReason').getProxy().url = 'Services/DataMaster/AssetChangeReason/List?CHANGE_CATEGORY=DISMANTLE_SITE';
								                      Ext.getStore('Administration.AssetChangeReason').load();
								                    }
							                  }
						                },
										
										 {
								             xtype: 'fileuploadfield',
								            // id: 'attachrelocationsite',
								             emptyText: 'Select a document to upload...',
								             name:'FILE',
								             fieldLabel: 'ATTACHMENT FILE',
								             buttonText: 'Browse',
								             labelWidth: 130/1366*screen.width,
								             width: 325/1366*screen.width,
								             margin:'5 10 0 10'
							            },
										{
											xtype : 'button',
											text : 'PROCESS',
											id : 'processdismantlesite',
											margin : '5 10 10 10',
											handler : function() {
												this.up('form').getForm().submit({
																	waitMsg : 'Please Wait ....',
																	success : function(form,action) {
																		return_AssetChange(form, action,"assetdismantlesite");
											              			    refreshAssetChange('AssetChange.AssetChangeStore','./Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=DISMANTLE_SITE');
											              			    
											              			    Ext.getStore('AssetDataMaster.AssetNonSac').getProxy().url = './Services/AssetChange/Asset/From/Site/List?site_id='+Ext.getCmp("textSiteIdtDismantleSite").getValue();
											              			    Ext.getStore('AssetDataMaster.AssetNonSac').load();
											              			    tempDataNE("assetdismantlesite","AssetDataMaster.AssetNonSac");
																	},
																	failure : function(form,action) {
																		return_AssetChange(form, action,"assetdismantlesite");
											              			    refreshAssetChange('AssetChange.AssetChangeStore','./Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=DISMANTLE_SITE');
											              			    
												              			  Ext.getStore('AssetDataMaster.AssetNonSac').getProxy().url = './Services/AssetChange/Asset/From/Site/List?site_id='+Ext.getCmp("textSiteIdtDismantleSite").getValue();
												              			  Ext.getStore('AssetDataMaster.AssetNonSac').load();
												              			  tempDataNE("assetdismantlesite","AssetDataMaster.AssetNonSac");
																	}
																});
							            							
												}

										},
										{
											xtype : 'button',
											text : 'RESET',
											margin : '5 10 10 10',
											handler : function() {
												this.up('form').getForm().reset();
											}
										},
										{
							              	  xtype :'panel',
							              	  id    :'assetdismantlesite',
							              	  border: false,
							              	  
							             }]

							},
							{
								xtype : 'gridpanel',
								region : 'center',
								id : 'table_DismantleSite',
								height : 590,
								// width : 400,
								titleAlign : 'center',
								margin : '5 5 5 0',
								border : true,
								forceFit : true,
								columnLines : true,
								store : 'AssetChange.AssetChangeStore',
								selType : 'checkboxmodel',
								title : 'Dismantle Site',
								columns : [{dataIndex : 'change_category',text : 'CHANGE CATEGORY',align : 'left'},
								           {dataIndex : 'change_reason',text : 'REASON',align : 'left'}, 
								           {dataIndex : 'source_site_id',text : 'SOURCE SITE ID',align : 'left'},
								           {dataIndex : 'destination',text : 'DESTINATION',align : 'left'},
								           {
						                   	    xtype: 'actioncolumn',
						                   	    text : 'DOCUMENT',
						                   	    align : 'center',
						                   	    renderer: function (value, metadata, record) {
						                   	    	var document = record.get('document');
						                   	    	if (document=="null"){
						                   	    		this.items[0].icon = '';
						                   	    	}else{
						                   	    		var typefile=document.split(".");
						                   	    		 if (typefile[1]=="pdf"){ 
						                   	    			 this.items[0].icon = 'images/pdf-icon.png'; 
						                   	    		 }else if (typefile[1]=="docx" || typefile[1]=="doc"){
						                   	    			 this.items[0].icon = 'images/Word-icon.png';  
						                   	    		 }else if (typefile[1]=="xlsx" || typefile[1]=="xls"){ 
						                   	    			 this.items[0].icon = 'images/Excel-icon.png';  
						                   	    		 }
						                   	    	}
						                   	    },
						                   	    items: [{
						                   	        tooltip: 'Show Document',
						                   	        handler: function (grid, rowIndex, colIndex) {
						                   	        	openFIle(grid,rowIndex);
						                   	        }
						                   	    }]
						                   	}],
								listeners : {
									afterrender : function() {
										refreshDismantle('DISMANTLE_SITE');
									},

									itemdblclick : function(grid, record) {
										 var change_id = record.get('change_id');
										 console.log (change_id);
										 change_id_global = change_id;
						                		if(Ext.getCmp('panelDismantleSite').hidden == true) Ext.getCmp('panelDismantleSite').toggleCollapse(true);
						                		Ext.Ajax.request({
						                		    method: "GET",
						                		    dataType: "json",
						                		    url: "./Services/AssetChange/Change/Detail/"+change_id,
						                		    async: false	,
						                		    success: function(c) {
						                		    	var jsonResults= $.parseJSON(c.responseText);
						                		    	data = jsonResults.item[0];
						                		    	console.log (data);
						                		    	Ext.getCmp('panelDismantleSite').getForm().setValues(data);
						                		        }
						                		    });
						            	  Ext.getStore('AssetDataMaster.AssetNonSac').removeAll();
					                      Ext.getStore('AssetDataMaster.AssetNonSac').getProxy().url = './Services/AssetChange/Change/Details/List/'+change_id+'?start=0&limit=20';
					                      Ext.getStore('AssetDataMaster.AssetNonSac').load();
					                      ShowGridAsset("assetdismantlesite");      
		            	  	
									}

								},

								dockedItems : [
										{
											xtype : 'pagingtoolbar',
											dock : 'bottom',
											store : 'AssetChange.AssetChangeStore',
											displayInfo : true
										},
										{
											xtype : 'toolbar',
											dock : 'top',
											items : [
													{
														xtype : 'textfield',
														fieldLabel : 'KEYWORD',
														id : 'keyworddismantlesite',
														margin : '0 10 0 10',
														labelWidth : 60,
														enableKeyEvents : true,
														listeners : {
															keypress : function(
																	form, e) {
																if (e.getKey() == 13) {
																	var keyword = Ext.getCmp("keyworddismantlesite").getValue();
									                            	searchAssetChange('AssetChange.AssetChangeStore','./Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=DISMANTLE_NE&keyword=',keyword);
																}

															}
														}
													},
													{
														xtype : 'button',
														text : 'SEARCH',
														id : 'searchdismantlesite',
														margin : '0 30 0 0',
														handler : function() {
															var keyword = Ext.getCmp("keyworddismantlesite").getValue();
							                            	searchAssetChange('AssetChange.AssetChangeStore','./Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=DISMANTLE_NE&keyword=',keyword);
														}
													},
													{
														xtype : 'button',
														text : 'ADD NEW',
														margin : '0 20 0 0',
														handler : function() {
															if (Ext.getCmp('panelDismantleSite').hidden == true)
																Ext.getCmp('panelDismantleSite').toggleCollapse(true);
														}

													}, {
														xtype : 'button',
														text : 'DELETE',
														margin : '0 20 0 0'

													}, {
														xtype : 'button',
														text : 'REFRESH',
														margin : '0 20 0 0',
														handler : function() {
															refreshDismantle('DISMANTLE_SITE');
														}
													} ]
										} ]

							} ]
				});
